package com.hxkcloud.nurse.utils;

import android.util.Log;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;

/**
 * Created by Administrator on 2017/2/28.
 */

public class SendMsgUtils {
    /**
     * send @ message, only support group chat message
     *
     * @param content
     */
    public static void sendAtMessage(String content, String toChatUsername, String name, String headImg) {
        EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
       // EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
    /*    if (EMClient.getInstance().getCurrentUser().equals(group.getOwner()) && EaseAtMessageHelper.get().containsAtAll(content)) {
            message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL);
        } else {
            message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG,
                    EaseAtMessageHelper.get().atListToJsonArray(EaseAtMessageHelper.get().getAtMessageUsernames(content)));
        }*/
       /* message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG,
                EaseAtMessageHelper.get().atListToJsonArray(EaseAtMessageHelper.get().getAtMessageUsernames(content)));*/
        sendMessage(message, name, headImg);

    }

    private static void sendMessage(EMMessage message, String name, String headImg) {
        if (message == null) {
            return;
        }
/*        if (chatFragmentHelper != null) {
            //set extension
            chatFragmentHelper.onSetMessageAttributes(message);
        }*/
    /*    if (chatType == EaseConstant.CHATTYPE_GROUP) {
            message.setChatType(EMMessage.ChatType.GroupChat);
        } else if (chatType == EaseConstant.CHATTYPE_CHATROOM) {
            message.setChatType(EMMessage.ChatType.ChatRoom);
        }*/
        message.setChatType(EMMessage.ChatType.Chat);
        message.setAttribute("name", name);
        message.setAttribute("headImg", headImg);
        EMClient.getInstance().chatManager().sendMessage(message);

        message.setMessageStatusCallback(new EMCallBack() {
            @Override
            public void onSuccess() {
            }

            @Override
            public void onError(int i, String s) {
                Log.e("错误",s);
            }

            @Override
            public void onProgress(int i, String s) {

            }
        });

    }
}
